package com.microservice.stream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.handler.annotation.SendTo;

/**
 * @author:wesley
 */
@EnableBinding(value = {MySink.class,MySource.class})
public class MyReceiver {

    @StreamListener(MySink.input)
    public void process(Object obj){
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        System.out.println("process : "+obj);
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&");
    }



    @StreamListener(MySink.input2)
    @SendTo(MySource.output) //发送回执，说明已经接收到了
    public String process2(Book book){
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        System.out.println("process2 : "+ book.getName());
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        return "process2 is received";
    }

    /**
     * 接受process2 的回执
     * @param msg
     */
    @StreamListener(MySource.output)
    public void doReback(String msg){
        System.out.println("-----------------------");
        System.out.println(msg);
        System.out.println("-----------------------");
    }


}
